package com.ruoyi.wvp.controller;

import java.util.List;
import java.util.Date;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wvp.domain.ImageEvent;
import com.ruoyi.wvp.service.IImageEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.enums.DeletedEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 督导员图片推送Controller
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/wvp/event")
@Tag(name = "【督导员图片推送】管理")
public class ImageEventController extends BaseController{
    @Autowired
    private IImageEventService imageEventService;

    /**
     * 查询督导员图片推送列表
     */
    @Operation(summary = "查询督导员图片推送列表")
    @PreAuthorize("@ss.hasPermi('wvp:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImageEvent imageEvent) {
        Page<ImageEvent> page = getPage();
        imageEventService.pageList(page, imageEvent);
        return getTableDataInfo(page);
    }


    /**
     * 导出督导员图片推送列表
     */
    @Operation(summary = "导出督导员图片推送列表")
    @PreAuthorize("@ss.hasPermi('wvp:event:export')")
    @Log(title = "督导员图片推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void exportAll(HttpServletResponse response,ImageEvent imageEvent){
        List<ImageEvent> list = imageEventService.listAll(imageEvent);
        ExcelUtil<ImageEvent> util = new ExcelUtil<ImageEvent>(ImageEvent.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取督导员图片推送详细信息
     */
    @Operation(summary = "获取督导员图片推送详细信息")
    @PreAuthorize("@ss.hasPermi('wvp:event:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(imageEventService.getById(id));
    }

    /**
     * 新增督导员图片推送
     */
    @Operation(summary = "新增督导员图片推送")
    @PreAuthorize("@ss.hasPermi('wvp:event:add')")
    @Log(title = "督导员图片推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImageEvent imageEvent){
        imageEvent.setDeleted(DeletedEnum.NOMAL.getValue());
        imageEvent.setCreateBy(getUsername());
        imageEvent.setCreateTime(new Date());
        return toAjax(imageEventService.save(imageEvent));
    }

    /**
     * 修改督导员图片推送
     */
    @Operation(summary = "修改督导员图片推送")
    @PreAuthorize("@ss.hasPermi('wvp:event:edit')")
    @Log(title = "督导员图片推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImageEvent imageEvent){
         imageEvent.setUpdateBy(getUsername());
         imageEvent.setUpdateTime(new Date());
        return toAjax(imageEventService.updateById(imageEvent));
    }

    /**
     * 删除督导员图片推送
     */
    @Operation(summary = "删除督导员图片推送")
    @PreAuthorize("@ss.hasPermi('wvp:event:remove')")
    @Log(title = "督导员图片推送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) {
        QueryWrapper<ImageEvent> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",List.of(ids));
        ImageEvent imageEvent = new ImageEvent();
        imageEvent.setUpdateTime(new Date());
        imageEvent.setUpdateBy(getLoginUser().getUser().getUserName());
        imageEvent.setDeleted(DeletedEnum.DELETED.getValue());
        return toAjax(imageEventService.update(imageEvent,queryWrapper));
    }

}
